<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>未处理意见建议_02</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <link rel="stylesheet" href="../../layui/font/iconfont.eot">
    <script src="../../js/jquery-3.4.1.js"></script>
    <script src="../../mock/mock/mock-min.js"></script>
    <script src="../../js/jquery-3.4.1.js"></script>
    <script src="../../mock/mock1.js"></script>
    <style>
        .layui-input,
        .layui-textarea {
            width: auto;
            margin-right: 6px;
        }
        
        .layui-form-select .layui-input {
            padding-right: 0;
        }
        
        .chaxun {
            display: inline;
            /* width: auto; */
            margin-right: 20px;
        }
        
        .dignbuanniu {
            margin: 15px 0;
        }
        
        .dingbuyihang {
            padding: 0px 10px;
            margin-left: 40px;
            top: -15px;
            width: 140px;
        }
        /*水平竖直居中  */
        
        .juzhong {
            margin-top: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .xingzhengcunxinxitianjia {
            width: 60%;
        }
        
        .hanggao {
            margin: 40px 0px;
        }
        
        .xiangqingtitle {
            color: #999;
        }
        
        .xiangqingcontent {
            text-align: center;
            width: 50%;
        }
        
        .xiangqingjianjie {
            width: auto;
            text-align: left;
            text-indent: 40px;
            padding: 9px 40px;
        }
        
        .layui-form {
            top: 10px;
        }
        
        .query {
            display: inline-block;
            position: relative;
            right: -432px;
        }
        
        .layui-form-select .layui-edge {
            right: -26px;
        }
    </style>
    </style>
</head>

<body>
    <div style="padding: 20px; background-color: #f2f2f2">
        <div class="layui-card layui-col-space15" style="padding: 20px; background-color: #fff">
            <div class="layui-card-body">
                <div class="layui-col-xs6 layui-col-sm6 layui-col-md6 dignbuanniu">
                    <form class="layui-form" action="" lay-filter="saixuan">
                        <label class="layui-form-label dingbuyihang">
                                                    <select id="zhen1" name="townid" lay-verify="required" name="townId" lay-filter="zhen1">
                                                        <option value="">地区筛选(镇/街道)</option>
                                                    </select>
                                                </label>
                        <label class="layui-form-label dingbuyihang">
                                        <select name="villageId" lay-verify="required" id="cun1" name="villageId">
                                                        <option value="">地区筛选(村)</option>
                                                    </select>
                                        </label>
                    </form>
                </div>
                <!-- 顶部按钮 -->
                <div class=" query">
                    <input style="display:inline-block" id="keywords" type="text" name="title" required lay-verify="required" placeholder="查询内容或字段" autocomplete="off" class="layui-input">
                    <button class="layui-btn" lay-filter="formDemo" onclick="chaxun()"><i class="layui-icon layui-icon-search"></i>查询</button>
                </div>
                <!-- 底部表格 -->
                <table class="layui-hide" id="test" lay-filter="test"></table>
            </div>
        </div>
    </div>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">向上反馈</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">处理反馈-被退回过</a>
    </script>


    <script src="../../layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

    <script>
        var option
        var table
        layui.use(['table', 'form'], function() {
            table = layui.table;

            option = {
                elem: '#test',
                url: url + "general/feedback/queryUntreated",
                toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
                headers: {
                    token: localStorage.getItem('token')
                },
                size: "lg",
                where: {},
                limits: [10, 20, 50, 100, 200, 500],
                defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                parseData: function(res) {
                    //res 即为原始返回的数据
                    return {
                        code: 0, //解析接口状态
                        msg: res.msg, //解析提示文本
                        count: res.data.count, //解析数据长度
                        data: setdata(res.data.ntreatedlist), //解析数据列表
                    };
                },
                title: '用户数据表',
                cols: [
                    [{
                        type: 'checkbox',
                    }, {
                        type: "numbers",
                        title: '#',
                    }, {
                        field: 'townname',
                        title: '所属街道',
                    }, {
                        field: 'villagename',
                        title: '所属村',
                    }, {
                        field: 'title',
                        title: '反馈标题',

                    }, {
                        field: 'upMessage',
                        title: '反馈内容',
                    }, {
                        fixed: 'right',
                        title: '操作',
                        toolbar: '#barDemo',
                    }]
                ],
                page: true
            }




            table.render(option);

            tableIns = table.render(option);

            //头工具栏事件
            table.on('toolbar(test)', function(obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：' + data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选' : '未全选');
                        break;

                        //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function(obj) {
                console.log(obj)
                    //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('真的退回么', function(index) {
                        obj.del();
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    layer.open({
                        type: 1,
                        title: "删除",
                        offset: "auto",
                        content: `<div style="font-size: 15px;line-height: 100px;height: 100px;text-align: center;">你确定要向上反馈当前项吗</div>`,
                        area: ["350px", "200px"],
                        btn: ["确定", "取消"], //可以无限个按钮
                        btn1: function() {
                            var data = {}
                            data.id = obj.data.id
                            data.upMessage = obj.data.upMessage
                            $.ajax({
                                url: url + "general/feedback/upfeedback",
                                data: data,
                                method: "post",
                                success: function(data) {
                                    console.log(data)
                                    if (data.code === 200) {
                                        layer.closeAll();
                                        table.render(option)
                                        layer.msg(data.msg)
                                    } else {
                                        table.render(option)
                                        layer.msg("操作失败")
                                    }


                                },
                                error: function(err) {
                                    layer.msg("操作失败")
                                }
                            })
                        },
                        btn2: function() {
                            layer.msg("已取消操作");
                        },
                    });
                }
            });
        });

        function setdata(data) {
            console.log(data);
            data.forEach(item => {
                item.townname = gettown(item.townId).name
                item.villagename = getvillage(item.villageId).name
            });
            console.log(data)
            return data
        }

        function chaxun() {
            option.where.keywords = $('#keywords')[0].value
            console.log(option.where)
            table.render(option)
        }
    </script>

</body>

</html>